package com.wb.mianxiangduixiang.bms;

/**
 * @author 黄衡熙
 * @version 1.0
 * @date 2025年07月22日14:59
 */
public class LoanCreditAccount extends CreditAccount implements Loanable {
    private double loanAmount;

    public double getLoanAmount() {
        return loanAmount;
    }

    public void setLoanAmount(double loanAmount) {
        this.loanAmount = loanAmount;
    }

    @Override
    public void providerLoan(double money) {
        setLoanAmount(getLoanAmount()+money);
        setBalance(super.getBalance()+money);
        System.out.println("成功贷款："+money+"当前账户余额为:"+getBalance());

    }

    @Override
    public boolean payLoan(double money) {
        // 由于此处属于贷款的信用账户
        // 因此,还贷时要求考虑当前账户余额与信用额度
        if (money > loanAmount) {
            System.out.println("还款金额大于贷款金额，请查询贷款金额，再重新输入还款金额");
        }else {
            if (money <= (getLimit() + super.getBalance())) {
                if (super.getBalance() >= money) {
                    super.setBalance(super.getBalance() - money);
                    setLoanAmount(getLoanAmount() - money);
                    System.out.println("恭喜您，还款成功，当前您的信用账户余额为：" + super.getBalance() + " 可用信用额度还剩:" + this.getLimit());
                } else {
                    setLimit(getLimit() + super.getBalance() - money);
                    super.setBalance(getBalance() - money);
                    setLoanAmount(getLoanAmount() - money);
                    System.out.println("恭喜您，还款成功，当前您的信用账户余额为：" + super.getBalance() + " 可用信用额度还剩:" + this.getLimit());
                }
            } else {
                System.out.println("还款失败，当前账户余额加透支余额不足以支持您的取款");
            }
        }
        return false;
    }

    @Override
    public double queryLoan() {
        //查询贷款
        System.out.println("当前贷款金额为:"+getLoanAmount());
        // 查询当前贷款的金额
        return getLoanAmount();
    }
}